$(function(){
    showMenuURL();
})

function ajaxObj(url, type, data, successFn, errorFn, async) {
    var layer3 = layer.load(2);
	async = async ? true : async;
    $.ajax({
        url: url,
        type: type,
        data: data,
        async: async,
        dataType: 'json',
        success: function(data){
            layer.close(layer3);
            successFn(data);
        },
        error: function(){
            layer.alert("网络请求失败，请再次提交！", {icon: 2});
            layer.close(layer3);
        }
    })
}


function errorFn() {
    layer.alert("服务器发生错误，请联系管理员！", {icon: 2})
}


function getLocalTime(nS) {
    var now = new Date(parseInt(nS) * 1000);
    var yy = now.getFullYear();      //年
    var mm = now.getMonth() + 1;     //月
    var dd = now.getDate();          //日
    var hh = now.getHours();         //时
    var ii = now.getMinutes();       //分
    var ss = now.getSeconds();       //秒
    var dateTime = yy + "-";
    if (mm < 10) dateTime += "0";
    dateTime += mm + "-";
    if (dd < 10) dateTime += "0";
    dateTime += dd + " ";
    if (hh < 10) dateTime += "0";
//    dateTime += hh + ":";
//    if (ii < 10) dateTime += '0';
//    dateTime += ii + ":";
//    if (ss < 10) dateTime += '0';
//    dateTime += ss;
    return dateTime;
    //return new Date(parseInt(nS) * 1000).toLocaleString().replace(/年|月/g, "-").replace(/日/g, " ");
}


/**
 * 获取 Unix 时间戳
 * @param dateStr
 * @return string
 */
function dateToTime(dateStr) {
    if(dateStr == ""){
        return "";
    }
    dateStr = dateStr.toString();
    var newstr = dateStr.replace(/[年,月,日]/g, '/');
    var date = new Date(newstr);
    var time_str = date.getTime().toString();
    return time_str.substr(0, 10);
}


function showMenuURL(){
    if($('.u-nav-url').length){
        var href = $('.u-nav-url').attr('href');
        var targ = $('.v6-u-secend-nav a[href="' +  href + '"]');
        var targUl = targ.parent().parent();
        targ.parent().addClass('active');
        targUl.show();
        targUl.parent().addClass('active');
    }else{
        var url = window.location.pathname;
        var search = window.location.search;

        var targNav = $('a[href="' + url + search + '"]');
        if (targNav) {
            var parent = targNav.parent().parent();

            if (parent.hasClass('v6-u-first-nav')) {    //一级菜单
                targNav.parent().addClass('active');
            } else if (parent.hasClass('v6-u-secend-nav')) {    //二级菜单
                parent.show();
                parent.parent().addClass('active');
                targNav.parent().addClass('active');
            }
        }
    }
}